package com.wj.rspmproperty.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wj.rspmproperty.mapper.UserMapper;
import com.wj.rspmproperty.pojo.PageResult;
import com.wj.rspmproperty.pojo.User;
import com.wj.rspmproperty.pojo.vo.UnpaidOwner;
import com.wj.rspmproperty.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author WeiJin
 * @version 1.0
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public int insertUser(User user) throws DuplicateKeyException, Exception {
        int result = -1;
        return result = userMapper.insertUser(user);
    }

    @Override
    public PageResult<User> pageOfOwners(Integer current, Integer size) {
        PageHelper.startPage(current,size);
        Page<User> page = userMapper.owners();
        return PageResult.restPage(page);
    }

    @Override
    public int changeUserStatus(User user) {
        return userMapper.changeUserStatus(user);
    }

    @Override
    public User queryById(Integer id) {
        return userMapper.queryById(id);
    }

    @Override
    public PageResult<UnpaidOwner> pageOfUnpaidOwnerList(Integer current, Integer size, Integer typeId) {
      PageHelper.startPage(current,size);
      Page<UnpaidOwner> page= userMapper.unpaidOwnerList(typeId);
        return PageResult.restPage(page);
    }
}
